package com.ctrip.corp.obt.shard.loader;


import com.ctrip.corp.obt.shard.exception.ShardException;
import com.ctrip.corp.obt.shard.manager.DataShardSourceManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author marco.zheng
 * @version 1.0
 * @date 2022/01/14
 * @desc Abstract数据分片加载器
 * @see
 * @since 1.0
 */
@Slf4j
abstract class AbstractShardSourceLoader implements IShardSourceLoader, InitializingBean {

    private final DataShardSourceManager dataShardSourceManager;

    AbstractShardSourceLoader(DataShardSourceManager dataShardSourceManager) {
        this.dataShardSourceManager = dataShardSourceManager;
    }

    DataShardSourceManager getDataShardSourceManager() {
        return dataShardSourceManager;
    }

    @Override
    public void afterPropertiesSet() {
        try {
            // Startup加载
            loadOnStartup();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new ShardException("Load datasource error:" + ex.getMessage());
        }
    }
}
